package BuyerAgent;

import jade.core.behaviours.FSMBehaviour;

/**
 * This class is a Finite State Machine based composite behavior that helps to
 * schedule the behaviors of buyer agent. Behaviors of buyer agent comprise:
 * GetMainContainerLocation, MovingToMainContainer, BuyingTrees, and
 * ComingBackHomeContainer
 * 
 * @author DUY HAN PHAN
 * 
 */
public class PurchaseTransactionBehaviour extends FSMBehaviour {
	// states name
	private static final String GET_MAIN_CONTAINER_LOCATION = "GetMainContainerLocation";
	private static final String MOVING_TO_MAIN_CONTAINER = "MovingToMainContainer";
	private static final String BUYING_TREES = "BuyingTrees";
	private static final String COMING_BACK_HOME_CONTAINER = "ComingBackHomeContainer";

	Buyer buyerAgent;

	/**
	 * @param buyerAgent
	 */
	public PurchaseTransactionBehaviour(Buyer buyerAgent) {
		super(buyerAgent);
		this.buyerAgent = buyerAgent;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jade.core.behaviours.Behaviour#onStart()
	 */
	@Override
	public void onStart() {
		// Register states
		registerFirstState(new GetMainContainerLocationBehaviour(buyerAgent), GET_MAIN_CONTAINER_LOCATION);
		registerState(new MoveToMainContainerBehaviour(buyerAgent), MOVING_TO_MAIN_CONTAINER);
		registerState(new BuyTreesBehaviour(buyerAgent), BUYING_TREES);
		registerLastState(new ComeBackHomeContainerBehaviour(buyerAgent), COMING_BACK_HOME_CONTAINER);

		// Register transitions
		registerDefaultTransition(GET_MAIN_CONTAINER_LOCATION, MOVING_TO_MAIN_CONTAINER);
		registerTransition(MOVING_TO_MAIN_CONTAINER, MOVING_TO_MAIN_CONTAINER, 0);
		registerTransition(MOVING_TO_MAIN_CONTAINER, BUYING_TREES, 1);
		registerTransition(BUYING_TREES, BUYING_TREES, 0);
		registerTransition(BUYING_TREES, COMING_BACK_HOME_CONTAINER, 1);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jade.core.behaviours.FSMBehaviour#onEnd()
	 */
	@Override
	public int onEnd() {
		// Finish the purchaseTransaction
		// TODO show the result (empty wish list) or the rest of the wish list
		return super.onEnd();
	}
}
